<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>团队任务管理 - TaskFlow</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        /* 全局样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        :root {
            --primary: #3498db;
            --secondary: #2ecc71;
            --warning: #f39c12;
            --danger: #e74c3c;
            --dark: #2c3e50;
            --light: #ecf0f1;
            --gray: #95a5a6;
            --todo: #e74c3c;
            --inprogress: #f39c12;
            --done: #2ecc71;
        }
        
        body {
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
        }
        
        .container {
            width: 90%;
            max-width: 1400px;
            margin: 0 auto;
            padding: 0 15px;
        }
        
        /* 导航栏样式 */
        header {
            background-color: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            position: sticky;
            top: 0;
            z-index: 100;
        }
        
        .navbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 0;
        }
        
        .logo {
            display: flex;
            align-items: center;
            font-size: 24px;
            font-weight: bold;
            color: var(--primary);
        }
        
        .logo i {
            margin-right: 10px;
        }
        
        .nav-links {
            display: flex;
            list-style: none;
        }
        
        .nav-links li {
            margin-left: 25px;
        }
        
        .nav-links a {
            text-decoration: none;
            color: var(--dark);
            font-weight: 500;
            transition: color 0.3s;
        }
        
        .nav-links a:hover {
            color: var(--primary);
        }
        
        .nav-icons {
            display: flex;
            align-items: center;
        }
        
        .nav-icon {
            margin-left: 20px;
            font-size: 20px;
            cursor: pointer;
            position: relative;
        }
        
        .notification-count {
            position: absolute;
            top: -8px;
            right: -8px;
            background-color: var(--danger);
            color: white;
            border-radius: 50%;
            width: 18px;
            height: 18px;
            font-size: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        /* 主要内容区域 */
        .main-content {
            padding: 30px 0;
        }
        
        .dashboard {
            display: grid;
            grid-template-columns: 300px 1fr;
            gap: 30px;
        }
        
        /* 侧边栏样式 */
        .sidebar {
            background-color: white;
            border-radius: 10px;
            padding: 25px;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
            height: fit-content;
        }
        
        .sidebar-section {
            margin-bottom: 30px;
        }
        
        .sidebar-section h3 {
            margin-bottom: 15px;
            padding-bottom: 10px;
            border-bottom: 1px solid var(--light);
            color: var(--dark);
        }
        
        .team-members {
            list-style: none;
        }
        
        .team-member {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .member-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background-color: var(--primary);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            margin-right: 10px;
        }
        
        .member-info h4 {
            font-size: 14px;
            margin-bottom: 3px;
        }
        
        .member-info p {
            font-size: 12px;
            color: var(--gray);
        }
        
        .stats {
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        
        .stat-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 10px 15px;
            background-color: var(--light);
            border-radius: 8px;
        }
        
        .stat-label {
            font-size: 14px;
        }
        
        .stat-value {
            font-weight: bold;
            font-size: 18px;
        }
        
        /* 任务看板样式 */
        .board {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 25px;
        }
        
        .board-column {
            background-color: white;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
        }
        
        .column-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 1px solid var(--light);
        }
        
        .column-title {
            font-size: 18px;
            font-weight: 600;
        }
        
        .task-count {
            background-color: var(--light);
            color: var(--dark);
            border-radius: 20px;
            padding: 3px 10px;
            font-size: 14px;
        }
        
        .todo .column-title {
            color: var(--todo);
        }
        
        .inprogress .column-title {
            color: var(--inprogress);
        }
        
        .done .column-title {
            color: var(--done);
        }
        
        .tasks-list {
            min-height: 100px;
        }
        
        .task-card {
            background-color: white;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 15px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
            border-left: 4px solid var(--primary);
            cursor: move;
            transition: transform 0.2s, box-shadow 0.2s;
        }
        
        .task-card:hover {
            transform: translateY(-3px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        
        .task-card.high-priority {
            border-left-color: var(--danger);
        }
        
        .task-card.medium-priority {
            border-left-color: var(--warning);
        }
        
        .task-card.low-priority {
            border-left-color: var(--gray);
        }
        
        .task-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            margin-bottom: 10px;
        }
        
        .task-title {
            font-weight: 600;
            margin-bottom: 5px;
        }
        
        .task-priority {
            font-size: 12px;
            padding: 2px 8px;
            border-radius: 10px;
            color: white;
        }
        
        .high-priority .task-priority {
            background-color: var(--danger);
        }
        
        .medium-priority .task-priority {
            background-color: var(--warning);
        }
        
        .low-priority .task-priority {
            background-color: var(--gray);
        }
        
        .task-description {
            font-size: 14px;
            color: var(--dark);
            margin-bottom: 15px;
            line-height: 1.4;
        }
        
        .task-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 12px;
        }
        
        .task-assignee {
            display: flex;
            align-items: center;
        }
        
        .assignee-avatar {
            width: 25px;
            height: 25px;
            border-radius: 50%;
            background-color: var(--primary);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 10px;
            margin-right: 5px;
        }
        
        .task-due {
            display: flex;
            align-items: center;
            color: var(--gray);
        }
        
        .task-due.overdue {
            color: var(--danger);
            font-weight: bold;
        }
        
        .task-due i {
            margin-right: 5px;
        }
        
        .add-task-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 100%;
            padding: 12px;
            background-color: transparent;
            border: 2px dashed var(--light);
            border-radius: 8px;
            color: var(--gray);
            font-size: 14px;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .add-task-btn:hover {
            background-color: var(--light);
            color: var(--dark);
        }
        
        .add-task-btn i {
            margin-right: 8px;
        }
        
        /* 任务详情模态框 */
        .task-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 1000;
            justify-content: center;
            align-items: center;
        }
        
        .modal-content {
            background-color: white;
            width: 800px;
            max-width: 90%;
            max-height: 90vh;
            border-radius: 10px;
            overflow: hidden;
            display: flex;
            flex-direction: column;
        }
        
        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 20px;
            border-bottom: 1px solid var(--light);
        }
        
        .modal-title {
            font-size: 20px;
            font-weight: 600;
        }
        
        .close-modal {
            font-size: 24px;
            cursor: pointer;
            color: var(--gray);
        }
        
        .modal-body {
            padding: 20px;
            overflow-y: auto;
            flex: 1;
        }
        
        .modal-footer {
            padding: 15px 20px;
            border-top: 1px solid var(--light);
            display: flex;
            justify-content: flex-end;
            gap: 10px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
        }
        
        .form-control {
            width: 100%;
            padding: 10px 15px;
            border: 1px solid var(--light);
            border-radius: 6px;
            font-size: 14px;
        }
        
        textarea.form-control {
            min-height: 100px;
            resize: vertical;
        }
        
        .form-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
        }
        
        .btn {
            display: inline-block;
            padding: 10px 20px;
            background-color: var(--primary);
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 500;
            transition: background-color 0.3s;
        }
        
        .btn:hover {
            background-color: #2980b9;
        }
        
        .btn-secondary {
            background-color: var(--light);
            color: var(--dark);
        }
        
        .btn-secondary:hover {
            background-color: #dde4e6;
        }
        
        .btn-danger {
            background-color: var(--danger);
        }
        
        .btn-danger:hover {
            background-color: #c0392b;
        }
        
        /* 评论区域 */
        .comments-section {
            margin-top: 30px;
        }
        
        .comments-list {
            margin-bottom: 20px;
            max-height: 200px;
            overflow-y: auto;
        }
        
        .comment {
            display: flex;
            margin-bottom: 15px;
            padding-bottom: 15px;
            border-bottom: 1px solid var(--light);
        }
        
        .comment-avatar {
            width: 35px;
            height: 35px;
            border-radius: 50%;
            background-color: var(--primary);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            margin-right: 10px;
            flex-shrink: 0;
        }
        
        .comment-content {
            flex: 1;
        }
        
        .comment-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 5px;
        }
        
        .comment-author {
            font-weight: 600;
            font-size: 14px;
        }
        
        .comment-time {
            font-size: 12px;
            color: var(--gray);
        }
        
        .comment-text {
            font-size: 14px;
            line-height: 1.4;
        }
        
        .add-comment {
            display: flex;
        }
        
        .comment-input {
            flex: 1;
            padding: 10px 15px;
            border: 1px solid var(--light);
            border-radius: 6px;
            font-size: 14px;
            resize: vertical;
            min-height: 60px;
        }
        
        .comment-btn {
            margin-left: 10px;
            align-self: flex-end;
        }
        
        /* 响应式设计 */
        @media (max-width: 1024px) {
            .dashboard {
                grid-template-columns: 1fr;
            }
            
            .sidebar {
                display: none;
            }
        }
        
        @media (max-width: 768px) {
            .board {
                grid-template-columns: 1fr;
            }
            
            .nav-links {
                display: none;
            }
            
            .form-row {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <header>
        <div class="container">
            <nav class="navbar">
                <div class="logo">
                    <i class="fas fa-tasks"></i>
                    TaskFlow
                </div>
                <ul class="nav-links">
                    <li><a href="#" class="active">看板</a></li>
                    <li><a href="#">日历</a></li>
                    <li><a href="#">报告</a></li>
                    <li><a href="#">团队</a></li>
                    <li><a href="#">设置</a></li>
                </ul>
                <div class="nav-icons">
                    <div class="nav-icon">
                        <i class="fas fa-bell"></i>
                        <span class="notification-count">3</span>
                    </div>
                    <div class="nav-icon">
                        <i class="fas fa-user-circle"></i>
                    </div>
                </div>
            </nav>
        </div>
    </header>

    <!-- 主要内容区域 -->
    <main class="main-content">
        <div class="container">
            <div class="dashboard">
                <!-- 侧边栏 -->
                <aside class="sidebar">
                    <div class="sidebar-section">
                        <h3>团队成员</h3>
                        <ul class="team-members">
                            <li class="team-member">
                                <div class="member-avatar">张</div>
                                <div class="member-info">
                                    <h4>张三</h4>
                                    <p>项目经理</p>
                                </div>
                            </li>
                            <li class="team-member">
                                <div class="member-avatar">李</div>
                                <div class="member-info">
                                    <h4>李四</h4>
                                    <p>前端开发</p>
                                </div>
                            </li>
                            <li class="team-member">
                                <div class="member-avatar">王</div>
                                <div class="member-info">
                                    <h4>王五</h4>
                                    <p>后端开发</p>
                                </div>
                            </li>
                            <li class="team-member">
                                <div class="member-avatar">赵</div>
                                <div class="member-info">
                                    <h4>赵六</h4>
                                    <p>UI设计师</p>
                                </div>
                            </li>
                        </ul>
                    </div>
                    
                    <div class="sidebar-section">
                        <h3>项目统计</h3>
                        <div class="stats">
                            <div class="stat-item">
                                <span class="stat-label">总任务数</span>
                                <span class="stat-value">24</span>
                            </div>
                            <div class="stat-item">
                                <span class="stat-label">已完成</span>
                                <span class="stat-value">8</span>
                            </div>
                            <div class="stat-item">
                                <span class="stat-label">进行中</span>
                                <span class="stat-value">10</span>
                            </div>
                            <div class="stat-item">
                                <span class="stat-label">逾期</span>
                                <span class="stat-value" style="color: var(--danger);">2</span>
                            </div>
                        </div>
                    </div>
                    
                    <div class="sidebar-section">
                        <h3>项目进度</h3>
                        <div class="progress-bar">
                            <div class="progress-track">
                                <div class="progress-fill" style="width: 65%;"></div>
                            </div>
                            <div class="progress-text">65% 完成</div>
                        </div>
                    </div>
                </aside>
                
                <!-- 任务看板 -->
                <section class="board">
                    <!-- 待办列 -->
                    <div class="board-column todo">
                        <div class="column-header">
                            <h3 class="column-title">待办</h3>
                            <span class="task-count">8</span>
                        </div>
                        <div class="tasks-list" id="todo-list">
                            <!-- 任务卡片将通过JavaScript动态生成 -->
                        </div>
                        <button class="add-task-btn" data-status="todo">
                            <i class="fas fa-plus"></i> 添加任务
                        </button>
                    </div>
                    
                    <!-- 进行中列 -->
                    <div class="board-column inprogress">
                        <div class="column-header">
                            <h3 class="column-title">进行中</h3>
                            <span class="task-count">10</span>
                        </div>
                        <div class="tasks-list" id="inprogress-list">
                            <!-- 任务卡片将通过JavaScript动态生成 -->
                        </div>
                        <button class="add-task-btn" data-status="inprogress">
                            <i class="fas fa-plus"></i> 添加任务
                        </button>
                    </div>
                    
                    <!-- 已完成列 -->
                    <div class="board-column done">
                        <div class="column-header">
                            <h3 class="column-title">已完成</h3>
                            <span class="task-count">6</span>
                        </div>
                        <div class="tasks-list" id="done-list">
                            <!-- 任务卡片将通过JavaScript动态生成 -->
                        </div>
                        <button class="add-task-btn" data-status="done">
                            <i class="fas fa-plus"></i> 添加任务
                        </button>
                    </div>
                </section>
            </div>
        </div>
    </main>

    <!-- 任务详情/编辑模态框 -->
    <div class="task-modal" id="task-modal">
        <div class="modal-content">
            <div class="modal-header">
                <h3 class="modal-title" id="modal-title">任务详情</h3>
                <span class="close-modal" id="close-modal">&times;</span>
            </div>
            <div class="modal-body">
                <form id="task-form">
                    <input type="hidden" id="task-id">
                    <div class="form-group">
                        <label for="task-title">任务标题</label>
                        <input type="text" id="task-title" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label for="task-description">任务描述</label>
                        <textarea id="task-description" class="form-control"></textarea>
                    </div>
                    <div class="form-row">
                        <div class="form-group">
                            <label for="task-priority">优先级</label>
                            <select id="task-priority" class="form-control">
                                <option value="low">低</option>
                                <option value="medium">中</option>
                                <option value="high">高</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="task-assignee">负责人</label>
                            <select id="task-assignee" class="form-control">
                                <option value="张">张三</option>
                                <option value="李">李四</option>
                                <option value="王">王五</option>
                                <option value="赵">赵六</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-row">
                        <div class="form-group">
                            <label for="task-due-date">截止日期</label>
                            <input type="date" id="task-due-date" class="form-control">
                        </div>
                        <div class="form-group">
                            <label for="task-status">状态</label>
                            <select id="task-status" class="form-control">
                                <option value="todo">待办</option>
                                <option value="inprogress">进行中</option>
                                <option value="done">已完成</option>
                            </select>
                        </div>
                    </div>
                    
                    <div class="comments-section">
                        <h3>评论</h3>
                        <div class="comments-list" id="comments-list">
                            <!-- 评论将通过JavaScript动态生成 -->
                        </div>
                        <div class="add-comment">
                            <textarea class="comment-input" id="comment-input" placeholder="添加评论..."></textarea>
                            <button type="button" class="btn comment-btn" id="add-comment-btn">发送</button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-secondary" id="cancel-btn">取消</button>
                <button class="btn btn-danger" id="delete-btn">删除</button>
                <button class="btn" id="save-btn">保存</button>
            </div>
        </div>
    </div>

    <script>
        // 模拟任务数据
        let tasks = [
            {
                id: 1,
                title: "设计用户登录界面",
                description: "创建用户登录和注册页面的UI设计",
                priority: "high",
                assignee: "赵",
                dueDate: "2023-06-15",
                status: "todo",
                comments: [
                    { author: "张", text: "请确保设计符合我们的品牌指南", time: "2023-06-01 10:30" },
                    { author: "赵", text: "已完成初稿，请查看", time: "2023-06-02 14:15" }
                ]
            },
            {
                id: 2,
                title: "实现用户认证API",
                description: "开发用户注册、登录和权限验证的后端API",
                priority: "high",
                assignee: "王",
                dueDate: "2023-06-20",
                status: "inprogress",
                comments: [
                    { author: "王", text: "已完成JWT token生成逻辑", time: "2023-06-05 09:45" }
                ]
            },
            {
                id: 3,
                title: "开发任务管理前端组件",
                description: "创建任务卡片、看板和模态框的React组件",
                priority: "medium",
                assignee: "李",
                dueDate: "2023-06-18",
                status: "inprogress",
                comments: []
            },
            {
                id: 4,
                title: "项目需求分析会议",
                description: "与客户讨论项目需求和功能规格",
                priority: "medium",
                assignee: "张",
                dueDate: "2023-06-10",
                status: "done",
                comments: [
                    { author: "张", text: "会议记录已上传到共享文件夹", time: "2023-06-10 16:20" }
                ]
            },
            {
                id: 5,
                title: "数据库设计",
                description: "设计应用程序的数据库结构和关系",
                priority: "medium",
                assignee: "王",
                dueDate: "2023-06-12",
                status: "done",
                comments: []
            },
            {
                id: 6,
                title: "编写单元测试",
                description: "为核心功能编写单元测试用例",
                priority: "low",
                assignee: "李",
                dueDate: "2023-06-25",
                status: "todo",
                comments: []
            }
        ];

        // DOM元素
        const todoList = document.getElementById('todo-list');
        const inprogressList = document.getElementById('inprogress-list');
        const doneList = document.getElementById('done-list');
        const taskModal = document.getElementById('task-modal');
        const closeModal = document.getElementById('close-modal');
        const cancelBtn = document.getElementById('cancel-btn');
        const saveBtn = document.getElementById('save-btn');
        const deleteBtn = document.getElementById('delete-btn');
        const taskForm = document.getElementById('task-form');
        const modalTitle = document.getElementById('modal-title');
        const addTaskBtns = document.querySelectorAll('.add-task-btn');
        const commentsList = document.getElementById('comments-list');
        const commentInput = document.getElementById('comment-input');
        const addCommentBtn = document.getElementById('add-comment-btn');

        // 当前编辑的任务ID
        let currentTaskId = null;

        // 初始化页面
        function init() {
            renderTasks();
            setupEventListeners();
        }

        // 渲染任务到看板
        function renderTasks() {
            // 清空列表
            todoList.innerHTML = '';
            inprogressList.innerHTML = '';
            doneList.innerHTML = '';
            
            // 更新任务计数
            document.querySelector('.todo .task-count').textContent = 
                tasks.filter(task => task.status === 'todo').length;
            document.querySelector('.inprogress .task-count').textContent = 
                tasks.filter(task => task.status === 'inprogress').length;
            document.querySelector('.done .task-count').textContent = 
                tasks.filter(task => task.status === 'done').length;
            
            // 渲染每个任务
            tasks.forEach(task => {
                const taskCard = createTaskCard(task);
                
                switch(task.status) {
                    case 'todo':
                        todoList.appendChild(taskCard);
                        break;
                    case 'inprogress':
                        inprogressList.appendChild(taskCard);
                        break;
                    case 'done':
                        doneList.appendChild(taskCard);
                        break;
                }
            });
        }

        // 创建任务卡片
        function createTaskCard(task) {
            const taskCard = document.createElement('div');
            taskCard.className = `task-card ${task.priority}-priority`;
            taskCard.setAttribute('data-id', task.id);
            
            // 检查是否逾期
            const today = new Date().toISOString().split('T')[0];
            const isOverdue = task.dueDate && task.dueDate < today && task.status !== 'done';
            
            taskCard.innerHTML = `
                <div class="task-header">
                    <div>
                        <div class="task-title">${task.title}</div>
                        <span class="task-priority">${getPriorityText(task.priority)}</span>
                    </div>
                </div>
                <div class="task-description">${task.description}</div>
                <div class="task-footer">
                    <div class="task-assignee">
                        <div class="assignee-avatar">${task.assignee}</div>
                        <span>${getAssigneeName(task.assignee)}</span>
                    </div>
                    <div class="task-due ${isOverdue ? 'overdue' : ''}">
                        <i class="far fa-calendar-alt"></i>
                        ${task.dueDate ? formatDate(task.dueDate) : '无'}
                    </div>
                </div>
            `;
            
            // 添加点击事件
            taskCard.addEventListener('click', () => {
                openTaskModal(task.id);
            });
            
            return taskCard;
        }

        // 打开任务模态框
        function openTaskModal(taskId = null) {
            currentTaskId = taskId;
            
            if (taskId) {
                // 编辑现有任务
                const task = tasks.find(t => t.id === taskId);
                if (task) {
                    document.getElementById('task-id').value = task.id;
                    document.getElementById('task-title').value = task.title;
                    document.getElementById('task-description').value = task.description;
                    document.getElementById('task-priority').value = task.priority;
                    document.getElementById('task-assignee').value = task.assignee;
                    document.getElementById('task-due-date').value = task.dueDate;
                    document.getElementById('task-status').value = task.status;
                    
                    modalTitle.textContent = '编辑任务';
                    deleteBtn.style.display = 'inline-block';
                    
                    // 渲染评论
                    renderComments(task.comments);
                }
            } else {
                // 创建新任务
                document.getElementById('task-id').value = '';
                document.getElementById('task-title').value = '';
                document.getElementById('task-description').value = '';
                document.getElementById('task-priority').value = 'medium';
                document.getElementById('task-assignee').value = '张';
                document.getElementById('task-due-date').value = '';
                document.getElementById('task-status').value = 'todo';
                
                modalTitle.textContent = '创建新任务';
                deleteBtn.style.display = 'none';
                
                // 清空评论
                commentsList.innerHTML = '';
            }
            
            taskModal.style.display = 'flex';
        }

        // 渲染评论
        function renderComments(comments) {
            commentsList.innerHTML = '';
            
            if (comments.length === 0) {
                commentsList.innerHTML = '<p>暂无评论</p>';
                return;
            }
            
            comments.forEach(comment => {
                const commentElement = document.createElement('div');
                commentElement.className = 'comment';
                commentElement.innerHTML = `
                    <div class="comment-avatar">${comment.author}</div>
                    <div class="comment-content">
                        <div class="comment-header">
                            <span class="comment-author">${getAssigneeName(comment.author)}</span>
                            <span class="comment-time">${comment.time}</span>
                        </div>
                        <div class="comment-text">${comment.text}</div>
                    </div>
                `;
                commentsList.appendChild(commentElement);
            });
        }

        // 设置事件监听器
        function setupEventListeners() {
            // 关闭模态框
            closeModal.addEventListener('click', () => {
                taskModal.style.display = 'none';
            });
            
            cancelBtn.addEventListener('click', () => {
                taskModal.style.display = 'none';
            });
            
            // 点击模态框外部关闭
            window.addEventListener('click', (e) => {
                if (e.target === taskModal) {
                    taskModal.style.display = 'none';
                }
            });
            
            // 保存任务
            saveBtn.addEventListener('click', () => {
                saveTask();
            });
            
            // 删除任务
            deleteBtn.addEventListener('click', () => {
                if (confirm('确定要删除这个任务吗？')) {
                    deleteTask();
                }
            });
            
            // 添加任务按钮
            addTaskBtns.forEach(btn => {
                btn.addEventListener('click', () => {
                    const status = btn.getAttribute('data-status');
                    openTaskModal();
                    document.getElementById('task-status').value = status;
                });
            });
            
            // 添加评论
            addCommentBtn.addEventListener('click', () => {
                addComment();
            });
            
            // 按Enter键添加评论
            commentInput.addEventListener('keypress', (e) => {
                if (e.key === 'Enter' && !e.shiftKey) {
                    e.preventDefault();
                    addComment();
                }
            });
        }

        // 保存任务
        function saveTask() {
            const taskId = document.getElementById('task-id').value;
            const title = document.getElementById('task-title').value;
            const description = document.getElementById('task-description').value;
            const priority = document.getElementById('task-priority').value;
            const assignee = document.getElementById('task-assignee').value;
            const dueDate = document.getElementById('task-due-date').value;
            const status = document.getElementById('task-status').value;
            
            if (!title.trim()) {
                alert('请输入任务标题');
                return;
            }
            
            if (taskId) {
                // 更新现有任务
                const taskIndex = tasks.findIndex(t => t.id === parseInt(taskId));
                if (taskIndex !== -1) {
                    tasks[taskIndex] = {
                        ...tasks[taskIndex],
                        title,
                        description,
                        priority,
                        assignee,
                        dueDate,
                        status
                    };
                }
            } else {
                // 创建新任务
                const newId = tasks.length > 0 ? Math.max(...tasks.map(t => t.id)) + 1 : 1;
                tasks.push({
                    id: newId,
                    title,
                    description,
                    priority,
                    assignee,
                    dueDate,
                    status,
                    comments: []
                });
            }
            
            renderTasks();
            taskModal.style.display = 'none';
        }

        // 删除任务
        function deleteTask() {
            if (currentTaskId) {
                tasks = tasks.filter(task => task.id !== currentTaskId);
                renderTasks();
                taskModal.style.display = 'none';
            }
        }

        // 添加评论
        function addComment() {
            const commentText = commentInput.value.trim();
            
            if (!commentText) {
                alert('请输入评论内容');
                return;
            }
            
            if (!currentTaskId) {
                alert('无法添加评论，任务未保存');
                return;
            }
            
            const task = tasks.find(t => t.id === currentTaskId);
            if (task) {
                const now = new Date();
                const timeString = `${now.getFullYear()}-${(now.getMonth()+1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')} ${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`;
                
                task.comments.push({
                    author: '张', // 假设当前用户是张三
                    text: commentText,
                    time: timeString
                });
                
                renderComments(task.comments);
                commentInput.value = '';
            }
        }

        // 工具函数
        function getPriorityText(priority) {
            switch(priority) {
                case 'high': return '高优先级';
                case 'medium': return '中优先级';
                case 'low': return '低优先级';
                default: return '普通';
            }
        }

        function getAssigneeName(assignee) {
            switch(assignee) {
                case '张': return '张三';
                case '李': return '李四';
                case '王': return '王五';
                case '赵': return '赵六';
                default: return '未知';
            }
        }

        function formatDate(dateString) {
            if (!dateString) return '';
            const date = new Date(dateString);
            return `${date.getMonth()+1}/${date.getDate()}`;
        }

        // 初始化应用
        init();
    </script>
</body>
</html>